"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useTran = exports.useQuery = void 0;
const conn_1 = require("./conn");
const utils_1 = require("./utils");
/**
 * 封装对应外部访问的操作类
 */
/**
 * sql语句方式访问数据库
 * @param mapperName sql文件名称
 * @param sqlName 对应的sql处理语句名称
 * @param paramsData 操作数据
 */
async function useQuery(mapperName, sqlName, paramsData) {
    let result;
    const { sql, params } = utils_1.getMapper(mapperName, sqlName);
    let ps = utils_1.transParams(params, paramsData);
    result = utils_1.getObj(await conn_1.query(sql, ps));
    return result;
}
exports.useQuery = useQuery;
/**
 * 通过事物操作访问数据库
 * @param mapperName sql文件名称
 * @param sqlNames 对应的sql处理语句名称
 * @param paramsData 操作数据
 */
async function useTran(mapperName, sqlNames, paramsData) {
    let sqlList = [];
    let paramsList = [];
    for (let i = 0; i < sqlNames.length; i++) {
        const sqlName = sqlNames[i];
        const { sql, params } = utils_1.getMapper(mapperName, sqlName);
        sqlList.push(sql);
        paramsList.push(params);
    }
    return utils_1.getObj(await conn_1.transaction(sqlList, paramsList, paramsData));
}
exports.useTran = useTran;
